% COMPAREHRC    'Fuse' function of heartrate calculation
% 
% Function: 
%           - If calculation of heartrate by using data of first order
%             differentiated data is not suitable and incorrect data
%             calculation, e.g. abnormal maximum and minimum,
%             i.e. Real-time heartrate > 250 or < 35
%           
%             The function will check one more time by using original data
%             caluculation.
%               
% Modified at 28 Oct 2010
% Copyright: Group 8
%-------------------------------------------------------------------------
function [newHR newmov_HR] = comparehrc(sgo, HR, mov_HR, QRS)
if max(mov_HR) > 250 || min(mov_HR) < 35 || HR > 250 || HR < 35 || ...
       std(mov_HR) > 20
   [newHR newmov_HR] = hrc(sgo(5500:35000));
   for index = 0:1:10
        if (length(newmov_HR) <= 30)
            [newHR, newmov_HR] = hrc(sgo...
                                             (1650+index*1650:40958-....
                                             index*1650));
        end
   end
   if length(newmov_HR) > 10
        newmov_HR = movavgecg(newmov_HR);
   else
        newmov_HR = 'nil';
   end
else
   newHR = HR;
   newmov_HR = mov_HR;
end
